package com.tiancheng.onecode.controller.admin;

import com.tiancheng.onecode.model.request.admin.PlatformAddReq;
import com.tiancheng.onecode.model.request.admin.PlatformQueryReq;
import com.tiancheng.onecode.model.request.admin.PlatformUpdateReq;
import com.tiancheng.onecode.model.response.PageInfo;
import com.tiancheng.onecode.model.response.Result;
import com.tiancheng.onecode.model.response.admin.PlatformQueryRes;
import com.tiancheng.onecode.service.IPlatformService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: kellen
 * @Description: 平台管理 admin controller
 * @Date: create in 2024/12/9 21:27
 */
@RestController
@RequestMapping("/admin/platform")
public class PlatformAdminController {

    @Resource
    private IPlatformService platformService;

    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ResponseBody
    public Result<PageInfo<PlatformQueryRes>> queryPage(@RequestBody PlatformQueryReq params) {
        PageInfo<PlatformQueryRes> pageInfo = platformService.queryPage(params);
        return Result.success(pageInfo);
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    @ResponseBody
    public Result<Boolean> add(@RequestBody PlatformAddReq params) {
        boolean success=platformService.add(params);
        return Result.success(success);
    }

    @RequestMapping(value = "/", method = RequestMethod.PUT)
    @ResponseBody
    public Result<Boolean> update(@RequestBody PlatformUpdateReq params) {
        boolean success=platformService.updatePlatform(params);
        return Result.success(success);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Result<PlatformQueryRes> getById(@PathVariable Long id) {
        PlatformQueryRes data=platformService.queryById(id);
        return Result.success(data);
    }
}
